Skip to content

build: add rust target for macOS cross compiles#63015

Merged
nodejs-github-bot merged 1 commit intonodejs:mainfrom
richardlau:macosrust
Apr 30, 2026
Merged

build: add rust target for macOS cross compiles#63015
nodejs-github-bot merged 1 commit intonodejs:mainfrom
richardlau:macosrust

Conversation

@richardlau
Copy link
Copy Markdown
Member

When we build the macOS pkg, we build Node.js twice (on arm64):

  • Once for arm64 (native)
  • Once for x64, using a combination of Rosetta 2 and compiler flags

before combining both into a universal binary.

For the x64 case, pass target flag to rustc so that the binary is built for the correct target architecture.


This is a "blind" attempt to address pkg build failures in the Node.js release CI -- I'm not a macOS user, nor do I have access to a macOS environment outside of the Node.js CI, so opening as a draft to test out.

It's quite possible that even if this is the "correct" fix, we'll need x64 rustc libraries installed on the release macOS VMs (CI run will indicate).

@richardlau richardlau added the macos Issues and PRs related to the macOS platform / OSX. label Apr 28, 2026
@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. labels Apr 28, 2026
@richardlau
Copy link
Copy Markdown
Member Author

richardlau commented Apr 28, 2026

Tried a test build, but that failed due to the issue being addressed by #63006. I'll either need that to land and rebase this, or create another branch with that plus this to test.

@richardlau
Copy link
Copy Markdown
Member Author

Trying with another branch with this PR and #63006:
https://ci-release.nodejs.org/job/iojs+release/11723/nodes=macos15-release-pkg/console

@richardlau richardlau force-pushed the macosrust branch 2 times, most recently from 161a312 to ff3dccc Compare April 28, 2026 19:59
@richardlau
Copy link
Copy Markdown
Member Author

Didn't work.
Trying again with target set for the actual compilation and not configure step: https://ci-release.nodejs.org/job/iojs+release/11724/nodes=macos15-release-pkg/

@richardlau
Copy link
Copy Markdown
Member Author

Didn't work. Trying again with target set for the actual compilation and not configure step: https://ci-release.nodejs.org/job/iojs+release/11724/nodes=macos15-release-pkg/

21:12:48    Compiling stable_deref_trait v1.2.1
21:12:48 error[E0463]: can't find crate for `core`
21:12:48   |
21:12:48   = note: the `x86_64-apple-darwin` target may not be installed
21:12:48   = help: consider downloading the target with `rustup target add x86_64-apple-darwin`
21:12:48 
21:12:48 For more information about this error, try `rustc --explain E0463`.
21:12:48 error: could not compile `stable_deref_trait` (lib) due to 1 previous error
21:12:48 warning: build failed, waiting for other jobs to finish...

@richardlau
Copy link
Copy Markdown
Member Author

Didn't work. Trying again with target set for the actual compilation and not configure step: https://ci-release.nodejs.org/job/iojs+release/11724/nodes=macos15-release-pkg/

21:12:48    Compiling stable_deref_trait v1.2.1
21:12:48 error[E0463]: can't find crate for `core`
21:12:48   |
21:12:48   = note: the `x86_64-apple-darwin` target may not be installed
21:12:48   = help: consider downloading the target with `rustup target add x86_64-apple-darwin`
21:12:48 
21:12:48 For more information about this error, try `rustc --explain E0463`.
21:12:48 error: could not compile `stable_deref_trait` (lib) due to 1 previous error
21:12:48 warning: build failed, waiting for other jobs to finish...

So this suggests we need to add the x64 macOS rust target to the VMs similar to the arm64 Windows targets for the Windows machines in nodejs/build#4285.

Further test builds have also errored with

12:19:39 clang++: error: no such file or directory: '/Users/admin/build/ws/out/Release/obj/gen/release/libnode_crates.a'
12:19:39 make[2]: *** [/Users/admin/build/ws/out/Release/mksnapshot] Error 1

and that appears to be because if a target is set it changes the directory that the compiled library is written to, which was accounted for in #61806. However this PR isn't adapting the Windows solution because the way the pkg is currently compiled, under Rosetta the host_arch is x64 so it's not going to be as easy to detect that we are cross-compiling.

Comment thread configure.py Outdated
When we build the macOS pkg, we build Node.js twice (on arm64):
- Once for arm64 (native)
- Once for x64, using a combination of Rosetta 2 and compiler flags

before combining both into a universal binary.

For the x64 case, pass target flag to `rustc` so that the binary is
built for the correct target architecture.

Signed-off-by: Richard Lau <[email protected]>
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@sxa
Copy link
Copy Markdown
Member

sxa commented Apr 30, 2026

Latest build from this branch with the addition of the x64 rust target succeeded at https://ci-release.nodejs.org/job/iojs+release/nodes=macos15-release-pkg/11740 and I've verified that temporal works in both architectures on the universal binary within the package :-)

@richardlau richardlau marked this pull request as ready for review April 30, 2026 11:55
@richardlau
Copy link
Copy Markdown
Member Author

Marking this ready for review.
As it stands it needs to have the x86_64-apple-darwin target added onto the macOS VMs (nodejs/build#4316).
I'll open another PR with the workaround we've been using to test that should only land if the build PR doesn't land in time for the 26.0.0 release.

Copy link
Copy Markdown
Member

@sxa sxa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM although Memo to self; I'd like to look in the future at whether we could use STATIC_LIB_PREFIX/SUFFIX instead of hard coding it in here as that could simplify the logic (Maybe @StefanStojanovic knows?)

@richardlau
Copy link
Copy Markdown
Member Author

LGTM although Memo to self; I'd like to look in the future at whether we could use STATIC_LIB_PREFIX/SUFFIX instead of hard coding it in here as that could simplify the logic (Maybe @StefanStojanovic knows?)

There is almost certainly room to streamline the logic across all platforms, but I've been just focussing on getting something to work with the minimal number of changes (to try to avoid breaking something else). As you say, we can revisit later on.

@RafaelGSS RafaelGSS added the fast-track PRs that do not need to wait for 72 hours to land. label Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Fast-track has been requested by @RafaelGSS. Please 👍 to approve.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 30, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 30, 2026
@nodejs-github-bot nodejs-github-bot merged commit 66054cc into nodejs:main Apr 30, 2026
97 checks passed
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Landed in 66054cc

@richardlau richardlau added dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. dont-land-on-v25.x PRs that should not land on the v25.x-staging branch and should not be released in v25.x. labels Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. build Issues and PRs related to build files or the CI. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. dont-land-on-v25.x PRs that should not land on the v25.x-staging branch and should not be released in v25.x. fast-track PRs that do not need to wait for 72 hours to land. macos Issues and PRs related to the macOS platform / OSX. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants